package com.yihu.wlyy.web.patient.hosptail;

import com.yihu.wlyy.entity.address.Hospital;
import com.yihu.wlyy.entity.address.Town;
import com.yihu.wlyy.entity.doctor.Doctor;
import com.yihu.wlyy.service.app.account.DoctorInfoService;
import com.yihu.wlyy.service.app.hospital.HospitalService;
import com.yihu.wlyy.web.BaseController;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Administrator on 2016.08.19.
 */
@Controller
@RequestMapping(value = "/hosptail")
public class HosptailWithOutFilterController extends BaseController {
    @Autowired
    private DoctorInfoService doctorInfoService;
    /**
     * 根据医院标识获取医生信息
     * @param hospital 医院标识
     * @param query 查询条件 ：医生名称
     * @param id
     * @param pageSize 页数
     * @return
     */
    @RequestMapping(value = "/doctor_list")
    @ResponseBody
    public String getDoctorByHospital(
            @RequestParam(required = false) String hospital,
            @RequestParam(required = false) String query,
            @RequestParam(required = true) long id,
            @RequestParam(required = true) Integer pageSize) {

        try {
            Page<Doctor> doctorList = doctorInfoService.getDoctorListByHospital(query, hospital, id, pageSize);
            JSONArray array = new JSONArray();
            if (doctorList != null) {
                for (Doctor doctor : doctorList) {
                    JSONObject json = new JSONObject();
                    json.put("id", doctor.getId());
                    json.put("code", doctor.getCode());
                    json.put("name", doctor.getName());
                    json.put("photo", doctor.getPhoto());
                    json.put("sex", doctor.getSex());
                    String sexName = "";
                    switch (doctor.getSex()) {
                        case 1:
                            sexName = "男";
                            break;
                        case 2:
                            sexName = "女";
                            break;
                    }
                    json.put("sexName", sexName);
                    json.put("job", doctor.getJob());
                    json.put("jobName", doctor.getJobName());
                    json.put("hospital", doctor.getHospital());
                    json.put("hospitalName", doctor.getHosptialName());
                    json.put("dept", doctor.getDept());
                    json.put("deptName", doctor.getDeptName());
                    array.put(json);
                }
            }
            return write(200, "查询成功！", "list", array);
        } catch (Exception ex) {
            error(ex);
            return error(-1, "查询失败！");
        }

    }
}
